import { getTheMarket } from "@/util/dxjsonp";
import { defineComponent, reactive, ref } from "vue";
import { bq } from "./emoji";
export default defineComponent({
  props: {
    code: {
      type: String,
    },
  },
  emits: ["getText"],
  setup(props, context) {
    const getPositionForTextArea = (ctrl) => {
      let CaretPos = 0;
      if (ctrl.selectionStart || ctrl.selectionStart == "0") {
        // Firefox support
        CaretPos = ctrl.selectionStart;
      }
      // console.log(CaretPos);
      return CaretPos;
    };
    const getTseert = (text: any) => {
      let position = document.getElementsByTagName("textarea")[0];
      let pos = getPositionForTextArea(position);
      console.log(pos);
      let y = position.value;
      console.log(y);
      let strfrontTfThe = y.substring(0, pos);
      let strhM = y.substring(pos, y.length);
      // position.focus();

      context.emit("getText", {
        evl: position,
        text: strfrontTfThe + text + strhM,
        pos: pos + 2,
      });
    };

    let emoji = ref(bq);
    return () => (
      <>
        <div class="niuhjjwet">
          {emoji.value.map((a) => {
            return (
              <div
                class="emjo-text"
                onClick={() => {
                  getTseert(a);
                }}
              >
                {a}
              </div>
            );
          })}
        </div>
      </>
    );
  },
});
